<template>
  <div class="major-wrap">
    <div>
      <div class='card' v-if="categoryList.length>0">
        <a v-for='(item,index) in categoryList' :key='index' href="javascript:void(0)" :class="index===currentIndex?'activeCategory':''" @click='categoryClick(index)' class="maoHref">{{item.name}}</a>
      </div>
      <no-content v-else :text="text"></no-content>
    </div>
    <div class="list-wrap scroll-wrap" id="listWrap">
      <div class='major-item' :id="item.id" :name="item.id" v-for="(item,index) in majorData" :key="index">
        <div class='item-category'>{{item.name}}</div>
        <div class="item-major" v-for="(sItem,sIndex) in item.majorSubCategories" :key="sIndex">
          <label class="major-name" for="" :title="sItem.name">{{sItem.name}}</label>
          <ul class="major">
            <li v-for="(mItem,mIndex) in sItem.majors" :key="mIndex">
              <a @click="toMajorDetail(mItem.id)" :title="mItem.name">{{mItem.name}}</a>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data () {
    return {
      // tabActiveIndex: 0,
      currentIndex: 0,
      // tabWidth: 126,
      scrollData: []
      // "'#'+item.id"
      // text: '正在加载数据...'
    }
  },
  props: {
    /*  currentIndex: {
       type: Number,
       default: 0
     }, */
    categoryList: {
      type: Array,
      default () {
        return []
      }
    },
    majorData: {
      type: Array,
      default () {
        return []
      }
    },
    // 控制专业详情推荐的显示隐藏
    pageTyp: {
      type: String,
      default () {
        return ''
      }
    },
    // 控制选科导航的选中状态
    fromPage: {
      type: String,
      default () {
        return ''
      }
    },
    text: {
      type: String,
      default () {
        return ''
      }
    },
    fromSchool: {
      type: String,
      default () {
        return ''
      }
    },
    collegeId: {
      default () {
        return 0
      }
    }
  },
  computed: {
    tripedPosition () {
      return `translate(${this.tabWidth * this.tabActiveIndex}px,0)`
    },
    type () {
      if (this.pageTyp === 'hide') {
        return 'hide'
      } else if (this.pageTyp === 'show') {
        return 'show'
      }
    }
  },
  methods: {
    toMajorDetail (id) {
      this.$router.push({
        path: 'major-detail',
        query: {
          id: id,
          pageType: this.type,
          fromPage: this.fromPage,
          fromSchool: this.fromSchool,
          collegeId: this.collegeId
        }
      })
    },
    categoryClick (index) {
      this.currentIndex = index
      let maoHref = document.querySelectorAll('.maoHref')
      this.removeMaoHref(maoHref[index])
      let listWrap = document.getElementById('listWrap')
      let childs = listWrap.querySelectorAll('.major-item')
      window.scrollTo(0, childs[index].offsetTop + 50)
    },
    // 清除锚链接
    removeMaoHref (obj) {
      location.replace(obj.href)
      return false
    }
  },
  mounted () {
  }
}
</script>
<style lang="scss" scoped>
.target-fix {
  position: relative;
  top: -60px; // 偏移为nav被fixed元素的高度
  display: block;
  height: 0; //高度为0
  overflow: hidden;
}
.major-wrap {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.tab-bar {
  position: relative;
  span {
    color: $stable02;
    font-size: 24px;
    cursor: pointer;
    &:not(:last-child) {
      margin-right: 30px;
    }
  }
  span.active {
    color: $dark01;
    position: relative;
  }
  .triped {
    height: 6px;
    width: 32px;
    position: absolute;
    left: 0;
    background: $energized;
    transition: all ease 0.35s;
  }
}
.card {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  align-items: center;
  &:after {
    display: block;
    clear: both;
    content: "";
  }
  &:before {
    content: "";
    position: absolute;
    left: 0;
    bottom: -10px;
    width: 100%;
    border-bottom: 1px solid $stable-ec;
  }
  .a-wrap {
    float: left;
    width: 80px;
    margin: 5px 0;
    &.small {
      width: 200px;
    }
  }
  a {
    font-size: $size16;
    padding: 2px;
    color: $dark;
    cursor: pointer;
    display: inline-block;
    margin: 15px 15px 10px 0;
  }
  .activeCategory {
    color: $light;
    background-color: $energized;
    transition: all ease 0.35s;
  }
}
.list-wrap {
  flex: 1;
}
.major-item {
  margin-top: -40px;
  padding-top: 60px;
  .item-category {
    color: $energized;
    font-size: 24px;
    margin-bottom: 15px;
    font-weight: bold;
  }
  .item-major {
    font-size: $size16;
    display: flex;
    align-items: flex-start;
    margin-bottom: 30px;
    .major-name {
      color: $stable02;
      // width: auto;
      // min-width: 150px;
      min-width: 100px;
      max-width: 100px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      line-height: 30px;
      display: inline-block;
    }
    .major {
      color: $dark;
      margin-left: 15px;
      width: 100%;
      li {
        float: left;
        /* min-width: 100px;
        width: auto; */
        line-height: 30px;
        text-align: left;
        max-width: 180px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        // width: 180px;
        // width: 200px;
        &:not(:last-child) {
          margin-right: 50px;
        }
      }
    }
  }
}
</style>
